<template>
  <div class="subject">
    <span>{{ a }}</span>
    <span>+</span>
    <span>{{ b }}</span>
    <span>=</span>
    <input type="number" v-model.number="num" />
    <button @click="submit">提交</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      num: null,
      status: "undo", // right  error  undo
    };
  },
  computed: {
    a() {
      return Math.floor(Math.random() * 11);
    },
    b() {
      return Math.floor(Math.random() * 11);
    },
  },
  methods: {
    submit(e) {
      if (this.num === null) {
          this.status = "undo";
          this.$emit("status-envent",this.status)
      } else if (this.num === this.a + this.b  ) {
          e.target.disabled = true;
          this.status = "right";
          this.$emit("status-envent",this.status)
      } else {
        e.target.disabled = true;
        this.status = "error";
        this.$emit("status-envent",this.status)
      }
    },
  },
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
.subject button {
  font-size: 16px;
  height: 26px;
  border: 1px solid #000;
  margin-left: 10px;
  background-color: #eee;
}
</style>
